package com.lankystar.todolist.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.lankystar.todolist.dao.GroupinfoMapper;
import com.lankystar.todolist.dao.GroupuserMapper;
import com.lankystar.todolist.model.Groupinfo;
import com.lankystar.todolist.model.Groupuser;
import com.lankystar.todolist.service.IGroupService;

@Component
public class GroupServiceImpl implements IGroupService {
	@Autowired
	private GroupinfoMapper groupInfoDao;
	@Autowired
	private GroupuserMapper groupUserDao;
	
	@Override
	public List<Groupinfo> selectGroup() {
		return this.groupInfoDao.selectGroups();
	}
	
	@Override
	public List<Groupuser> selectGroupUserById(Integer groupId) {
		return groupUserDao.selectGroupUsersByGroupId(groupId);
	}
	
	@Override
	public void createGroup(String name,String createTime) {
		int res=this.groupInfoDao.insertGroup(name, createTime);
		System.out.println(res);
	}

	@Override
	public Groupinfo selectGroupByName(String name) {
		return this.groupInfoDao.selectGroupByName(name);
	}
	
	@Override
	public void createGroupUser(Integer groupId,Integer userId,String role) {
		int res=this.groupUserDao.insertGroupuser(groupId, userId, role);
		System.out.println(res);
	}
	
	@Override
	public void deleteByGroupinfiId(Integer groupId) {
		groupUserDao.deleteByGroupinfiId(groupId);
		groupInfoDao.deleteByPrimaryKey(groupId);
		
	}

	@Override
	public void deleteGroupuserByUserId(Integer userId,Integer groupId) {
		this.groupUserDao.deleteGroupuserByUserId(userId,groupId);
	}

	@Override
	public Groupuser seleteGroupuserByUserIdAndGroupId(Integer userId, Integer groupId) {
		return this.groupUserDao.seleteGroupuserByUserIdAndGroupId(userId, groupId);
	}

	@Override
	public void upateGroupuser(Groupuser record) {
		this.groupUserDao.updateByPrimaryKeySelective(record);
	}

}
